from flask_marshmallow import base_fields
from flask_restplus_patched import ModelSchema
from app.modules.common.schemas import BaseSchema

from app.modules.agent.schemas import AgentBaseSchema


class MachineBaseSchema(ModelSchema):
    class Meta:
        fields = (
            "id",
            "ip",
            "cpus",
            "ram",
            "disks",
        )

        dump_only = (
            "id",
        )


class MachintInfoSchema(ModelSchema):
    agent_list = base_fields.Nested(
        AgentBaseSchema,
        many = True
    )

    class Meta(MachineBaseSchema.Meta):
        fields = MachineBaseSchema.Meta.fields + (
            'agent_list',
        )


class MachineListSchema(BaseSchema):
    data = base_fields.Nested(
        MachintInfoSchema,
        many = True
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )
